package com.power.using.mydaggerp.ui.activity.detial;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;

import com.bumptech.glide.Glide;
import com.power.using.mydaggerp.base.BasePresenter;
import com.power.using.mydaggerp.constant.BundleKeyConstant;
import com.power.using.mydaggerp.contract.detail.ZhihuDetailContract;
import com.power.using.mydaggerp.model.bean.zhihu.ZhihuDailyDetailBean;
import com.power.using.mydaggerp.presenter.detail.ZhihuDetailPresenter;
import com.zyw.horrarndoo.sdk.utils.HtmlUtils;

/**
 * Created by 聪明一只哈 on 2019/10/11.
 * Time: 2019/10/11  11:49
 */
public class ZhihuDailyDetailActivity
        extends BaseWebViewLoadActivity<
        ZhihuDetailContract.ZhihuDetailPresenter>
        implements ZhihuDetailContract.IZhihuDetialView {

    private String mId, mTitle;

    @Override
    protected void initData() {
        super.initData();
        Bundle bundle = getIntent().getExtras();
        if(bundle!=null){
            mId=bundle.getString(BundleKeyConstant.ARG_KEY_ZHIHU_DETAIL_ID);
            mTitle=bundle.getString(BundleKeyConstant.ARG_KEY_ZHIHU_DETAIL_TITLE);
        }
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        super.initView(savedInstanceState);
        tvDetailTitle.setText(mTitle);
    }

    @NonNull
    @Override
    public BasePresenter initPresenter() {
        return ZhihuDetailPresenter.newInstance();
    }

    @Override
    public void showDailyDetail(ZhihuDailyDetailBean bean) {

        flNetView.setVisibility(View.GONE);
        Glide.with(mContext).load(bean.getImage()).crossFade().into(ivDetail);
        tvDetailTitle.setText(bean.getTitle());
        tvDetailCopyright.setText(bean.getImage_source());
        String htmlData = HtmlUtils.createHtmlData(bean.getBody(), bean.getCss(), bean.getJs());
        nswvDetailContent.loadData(htmlData, HtmlUtils.MIME_TYPE, HtmlUtils.ENCODING);

    }

    @Override
    protected void loadDetail() {
        mPresenter.loadDailyDetail(mId);
    }

    @Override
    protected String getToolbarTitle() {
        return "知乎日报";//ResourcesUtils.getString(R.string.zhihu_detail_title)
    }
}
